{include file="common/header" title="增加"}
<div class="x-body">
    <form class="layui-form">
        <blockquote class="layui-elem-quote title"><button class="layui-btn" lay-filter="save" lay-submit=""><i class="seraph icon-caidan"></i>微语增加</button></blockquote>
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md4 layui-col-lg2 layui-col-xs-6" >
                <input type="hidden" id="testView" name="create_time" />
                <div id="test2"></div>
            </div>
            <div style="float:right;" id="editor" class="layui-col-md8 layui-col-lg9 layui-col-sx-6" ></div>
        </div>
    </form>
</div>

<script>
    layui.use(['form', 'layer','laydate'], function () {
        $ = layui.jquery;
        var form = layui.form
            , laydate = layui.laydate
            , layer = layui.layer;


        laydate.render({
            elem: '#test2'
            , position: 'static'
            ,value: new Date()
            , type: 'datetime'
            , ready: function (date) {
                lay('#testView').val(date.year + '-' + date.month + '-' + date.date + ' ' + date.hours + ':' + date.minutes + ':' + date.seconds);
            }
            , change: function (value, date, endDate) { //监听日期被切换
                lay('#testView').val(value);
            }
            ,done: function(value, date, endDate){
                lay('#testView').val(value);
            }
        });


        //自定义验证规则
        form.verify({
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_]+$").test(value)) {
                    return '只能由字母开头，并且包含数字或者下划线组成';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '用户名不能全为数字';
                }
                if (value.length < 5) {
                    return '管理员至少得5个字符啊';
                }
                if (value.length > 20) {
                    return '管理员不得超过20个字符啊';
                }
            }
            , password: [/([a-z0-9A-Z_]+){6,12}$/, '密码必须6到12位']
            , password_confirm: function (value) {
                if ($('#password').val() != $('#password_confirm').val()) {
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(save)', function (data) {
            data.field.digests = editor.txt.html();
            //发异步，把数据提交给php
            $.post('{:url("save")}', {data: data.field}, function (reg) {
                switch (reg.code) {
                    case 0:
                        layer.msg(reg.msg, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            // 可以对父窗口进行刷新
                            x_admin_father_reload();
                        });
                        break;
                    default:
                        layer.msg(reg.msg, {icon: 5});
                }

            }, 'json');
            return false;
        });


    });
</script>

<!-- 注意， 只需要引用 JS，无需引用任何 CSS ！！！-->
<script type="text/javascript" src="__COMMON__/lib/wangEditor/wangEditor.min.js"></script>
<script type="text/javascript">
    var E = window.wangEditor;
    var editor = new E('#editor');
    /*上传配置*/
    editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024; //最大上传大小为 3m
    editor.customConfig.uploadImgMaxLength = 5; //最多一次上传5张
    editor.customConfig.uploadFileName = 'file'; //上传的字段名
    editor.customConfig.uploadImgServer = '{:url("upload")}';

    /*创建实体化*/
    editor.create();

    //提示内容
    editor.customConfig.customAlert = function (info) {
        // info 是需要提示的内容
        layer.msg(info)
    }

</script>



</body>

</html>